package com.bestvike.stone.spring.stream.core;

import com.bestvike.stone.core.collection.ListUtils;
import org.springframework.cloud.stream.binding.MessageConverterConfigurer;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.cloud.stream.converter.CompositeMessageConverterFactory;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.messaging.MessageChannel;

/**
 * Created by 许崇雷 on 2018-09-03.
 */
public final class StreamMessageConverterConfigurer extends MessageConverterConfigurer {
    public StreamMessageConverterConfigurer(BindingServiceProperties bindingServiceProperties, CompositeMessageConverterFactory compositeMessageConverterFactory) {
        super(bindingServiceProperties, compositeMessageConverterFactory);
    }

    @Override
    public void configureInputChannel(MessageChannel messageChannel, String channelName) {
        super.configureInputChannel(messageChannel, channelName);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void configureOutputChannel(MessageChannel messageChannel, String channelName) {
        super.configureOutputChannel(messageChannel, channelName);
        AbstractMessageChannel channel = (AbstractMessageChannel) messageChannel;
        channel.setInterceptors(ListUtils.EMPTY_LIST);//清空拦截器,以强制使用 rabbitTemplateEx 的序列化转换器,参见 StreamRabbitMessageChannelBinder
    }
}
